package com.ruoyi.studentFinancial.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.studentFinancial.domain.XgStudentFinancial;
import com.ruoyi.studentFinancial.service.IXgStudentFinancialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生资助信息Controller
 * 
 * @author ruoyi
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/studentFinancial/studentFinancial")
public class XgStudentFinancialController extends BaseController
{
    @Autowired
    private IXgStudentFinancialService xgStudentFinancialService;

    /**
     * 查询学生资助信息列表
     */
    @PreAuthorize("@ss.hasPermi('studentFinancial:studentFinancial:list')")
    @GetMapping("/list")
    public TableDataInfo list(XgStudentFinancial xgStudentFinancial)
    {
        startPage();
        List<XgStudentFinancial> list = xgStudentFinancialService.selectXgStudentFinancialList(xgStudentFinancial);
        return getDataTable(list);
    }

    /**
     * 导出学生资助信息列表
     */
    @PreAuthorize("@ss.hasPermi('studentFinancial:studentFinancial:export')")
    @Log(title = "学生资助信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XgStudentFinancial xgStudentFinancial)
    {
        List<XgStudentFinancial> list = xgStudentFinancialService.selectXgStudentFinancialList(xgStudentFinancial);
        ExcelUtil<XgStudentFinancial> util = new ExcelUtil<XgStudentFinancial>(XgStudentFinancial.class);
        util.exportExcel(response, list, "学生资助信息数据");
    }

    /**
     * 获取学生资助信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('studentFinancial:studentFinancial:query')")
    @GetMapping(value = "/{sfId}")
    public AjaxResult getInfo(@PathVariable("sfId") Long sfId)
    {

        return success(xgStudentFinancialService.selectXgStudentFinancialBySfId(sfId));
    }

    /**
     * 新增学生资助信息
     */
    @PreAuthorize("@ss.hasPermi('studentFinancial:studentFinancial:add')")
    @Log(title = "学生资助信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XgStudentFinancial xgStudentFinancial)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        xgStudentFinancial.setDeptId(104L);
        xgStudentFinancial.setUserId(user.getUserId());
        return toAjax(xgStudentFinancialService.insertXgStudentFinancial(xgStudentFinancial));
    }

    /**
     * 修改学生资助信息
     */
    @PreAuthorize("@ss.hasPermi('studentFinancial:studentFinancial:edit')")
    @Log(title = "学生资助信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XgStudentFinancial xgStudentFinancial)
    {
        return toAjax(xgStudentFinancialService.updateXgStudentFinancial(xgStudentFinancial));
    }

    /**
     * 删除学生资助信息
     */
    @PreAuthorize("@ss.hasPermi('studentFinancial:studentFinancial:remove')")
    @Log(title = "学生资助信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sfIds}")
    public AjaxResult remove(@PathVariable Long[] sfIds)
    {
        return toAjax(xgStudentFinancialService.deleteXgStudentFinancialBySfIds(sfIds));
    }
}
